package com.mg.smarttask.client;


import com.google.gwt.core.client.EntryPoint;
//import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class LoginModule implements EntryPoint {
	boolean devmode = true;
	Login login;
	Subscribe subscribe; 
	Button lButton;
	Button sButton;
	InfoST infoST = new InfoST();
	NotesWindow notes = new NotesWindow();
	VideoWindow videos = new VideoWindow();
	HomeWindow accueil = new HomeWindow();
	TasksWindow taches = new TasksWindow();
	public VerticalPanel container;
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
		rootPanel.setSize("100%", "100%");
		subscribe = new Subscribe(this);
		login = new Login(this);
		VerticalPanel verticalPanel = new VerticalPanel();
		rootPanel.add(verticalPanel);
		verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.setWidth("100%");
		if(!this.userIsIn()) LoadNotLoggedIn(verticalPanel);
		else LoadLoggedIn(verticalPanel);
		
	}
	
	
	public void LoadLoggedIn(Panel verticalPanel){
		Label lblBienvenueSurSmartask = new Label("Bienvenue dans votre espace SmartTask");
		lblBienvenueSurSmartask.setStyleName("welcomeTitle");
		lblBienvenueSurSmartask.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		lblBienvenueSurSmartask.setDirectionEstimator(true);
		verticalPanel.add(lblBienvenueSurSmartask);
		lblBienvenueSurSmartask.setSize("100%\n", "70px");
		final VerticalPanel verticalPanel_1 = new VerticalPanel();
		container = verticalPanel_1;
		verticalPanel_1.setStyleName("mainVerticalPanel");
		verticalPanel_1.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
		verticalPanel_1.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.add(verticalPanel_1);
		verticalPanel_1.setWidth("700px");
		
		HorizontalPanel horizontalPanel_1 = new HorizontalPanel();
		horizontalPanel_1.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
		verticalPanel_1.add(horizontalPanel_1);
		horizontalPanel_1.setSize("700px", "100%");
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		horizontalPanel_1.add(horizontalPanel);
		horizontalPanel.setWidth("300px");
		
		final Button notesButton = new Button("Notes");
		notesButton.setStyleName("notesButton");
		final Button homeButton = new Button("Accueil");
		homeButton.setStyleName("homeButton");
		final Button tachesButton = new Button("Taches");
		tachesButton.setStyleName("tachesButton");
		final Button videosButton = new Button("Videos");
		videosButton.setStyleName("videosButton");
		notesButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				verticalPanel_1.remove(infoST);
				verticalPanel_1.remove(subscribe);
				verticalPanel_1.remove(login);
				verticalPanel_1.add(notes);
				notes.showNotes.loadNotesFromServer();
				notes.showNotes.updateNotePanel();
				tachesButton.removeStyleName("buttonActive");
				videosButton.removeStyleName("buttonActive");
				homeButton.removeStyleName("buttonActive");
				notesButton.addStyleName("buttonActive");
			}
		});	
		tachesButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				verticalPanel_1.remove(login);
				verticalPanel_1.remove(subscribe);
				verticalPanel_1.remove(notes);
				verticalPanel_1.add(infoST);
				notesButton.removeStyleName("buttonActive");
				videosButton.removeStyleName("buttonActive");
				tachesButton.addStyleName("buttonActive");
				homeButton.removeStyleName("buttonActive");
			}
		});

		videosButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				verticalPanel_1.remove(infoST);
				verticalPanel_1.remove(login);
				verticalPanel_1.remove(notes);
				verticalPanel_1.add(subscribe);
				notesButton.removeStyleName("buttonActive");
				tachesButton.removeStyleName("buttonActive");
				homeButton.removeStyleName("buttonActive");
				videosButton.addStyleName("buttonActive");
			}
		});
		homeButton.setSize("80px", "90px");
		horizontalPanel.add(homeButton);
		horizontalPanel.add(notesButton);
		notesButton.setSize("80px", "90px");
		horizontalPanel.add(tachesButton);
		tachesButton.setSize("80px", "90px");
		horizontalPanel.add(videosButton);
		videosButton.setSize("80px", "90px");
		//FIn des bouttons
		
		HorizontalPanel horizontalPanel_2 = new HorizontalPanel();
		horizontalPanel_2.setStyleName("mainButtonPanelSub");
		verticalPanel_1.add(horizontalPanel_2);
		horizontalPanel_2.setSize("100%", "5px");
		
		verticalPanel_1.add(infoST);
		infoST.setWidth("100%");
		
		login.setSize("700px", "148px");
		subscribe.setWidth("700px");				
		
	}
	
	public void LoadNotLoggedIn(Panel verticalPanel){
		Label lblBienvenueSurSmartask = new Label("Bienvenue sur SmartTask");
		lblBienvenueSurSmartask.setStyleName("welcomeTitle");
		lblBienvenueSurSmartask.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		lblBienvenueSurSmartask.setDirectionEstimator(true);
		verticalPanel.add(lblBienvenueSurSmartask);
		lblBienvenueSurSmartask.setSize("100%\n", "70px");
		
		final VerticalPanel verticalPanel_1 = new VerticalPanel();
		container = verticalPanel_1;
		verticalPanel_1.setStyleName("mainVerticalPanel");
		verticalPanel_1.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
		verticalPanel_1.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		verticalPanel.add(verticalPanel_1);
		verticalPanel_1.setWidth("700px");
		
		HorizontalPanel horizontalPanel_1 = new HorizontalPanel();
		horizontalPanel_1.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
		verticalPanel_1.add(horizontalPanel_1);
		horizontalPanel_1.setSize("700px", "100%");
		
		HorizontalPanel horizontalPanel = new HorizontalPanel();
		horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		horizontalPanel_1.add(horizontalPanel);
		horizontalPanel.setWidth("300px");
		
		final Button loginButton = new Button("Se connecter");
		final Button subscribeButton = new Button("S'inscrire");
		final Button infoButton = new Button("Info");
		infoButton.setStyleName("infoButton");
		infoButton.addStyleName("infoActive");
		
		loginButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				verticalPanel_1.remove(infoST);
				verticalPanel_1.remove(subscribe);
				verticalPanel_1.add(login);
				subscribeButton.removeStyleName("subscribeActive");
				infoButton.removeStyleName("infoActive");
				loginButton.addStyleName("loginActive");
			}
		});
		
		infoButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				verticalPanel_1.remove(login);
				verticalPanel_1.remove(subscribe);
				verticalPanel_1.add(infoST);
				loginButton.removeStyleName("loginActive");
				subscribeButton.removeStyleName("subscribeActive");
				infoButton.addStyleName("infoActive");
			}
		});
		
		horizontalPanel.add(infoButton);
		infoButton.setSize("80px", "90px");
		horizontalPanel.add(loginButton);
		loginButton.setStyleName("loginButton");
		loginButton.setText("Se connecter");
		loginButton.setSize("80px", "90px");
		lButton = loginButton;
		sButton = subscribeButton;
		subscribeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				verticalPanel_1.remove(infoST);
				verticalPanel_1.remove(login);
				verticalPanel_1.add(subscribe);
				loginButton.removeStyleName("loginActive");
				infoButton.removeStyleName("infoActive");
				subscribeButton.addStyleName("subscribeActive");
			}
		});
		subscribeButton.setStyleName("subscribeButton");
		horizontalPanel.add(subscribeButton);
		subscribeButton.setSize("80px", "90px");
		
		HorizontalPanel horizontalPanel_2 = new HorizontalPanel();
		horizontalPanel_2.setStyleName("mainButtonPanelSub");
		verticalPanel_1.add(horizontalPanel_2);
		horizontalPanel_2.setSize("100%", "5px");
		
		verticalPanel_1.add(infoST);
		infoST.setWidth("100%");
		
		login.setSize("700px", "148px");
		subscribe.setWidth("700px");				

	}
	
	private boolean userIsIn(){
		if(!this.devmode) return false;
		return false;
	}
	
}
